import axios from "axios";

export default {
  //新增店铺
  post(name, address, tel, business, time, status, hasDistribution) {
    return (
      axios
        //第1个stores是接口服务器下stores的路由(app.js)，再找路由下的stores
        .post("/stores/addStores", {
          name,
          address,
          tel,
          business,
          time,
          status,
          hasDistribution,
        })
        .then(function (response) {
          // console.log("api",response);
          return response.data;
        })
    );
  },
  //获取店铺信息
  get(curPage, eachPage) {
    return axios
      .get("/stores/getStores", {
        params: {
          curPage,
          eachPage,
        },
      })
      .then(function (response) {
        return response.data;
      });
  },
  //修改店铺信息
  editStores(name, address, tel, business, time, status, hasDistribution, _id) {
    return axios
      .post("/stores/editStores", {
        name,
        address,
        tel,
        business,
        time,
        status,
        hasDistribution,
        _id,
      })
      .then(function (response) {
        // console.log("api",response);
        return response.data;
      });
  },
  //删除店铺
  deleteStores(_id) {
    console.log("api", _id);
    return axios
      .delete("/stores/deleteStores", {
        params: {
          _id,
        },
      })
      .then(function (response) {
        // console.log("api",response);
        return response.data;
      });
  },
  //查询店铺
  searchStores(name, address, curpage, eachpage) {
    return axios
      .get("/stores/searchStores", {
        params: {
          name,
          address,
          curpage,
          eachpage,
        },
      })
      .then(function (response) {
        return response.data;
      });
  },
  //新增店铺商品
  postStShop(goodsInfo, storesId) {
    return (
      axios
        .post("/stores/addStShop", {
          goodsInfo, storesId
        })
        .then(function (response) {
          // console.log("api",response);
          return response.data;
        })
    );
  },
  //获取店铺商品列表
  getStShop(curPage, eachPage,storesId) {
    return axios
      .get("/stores/getStShop", {
        params: {
          curPage,
          eachPage,
          storesId
        },
      })
      .then(function (response) {
        return response.data;
      });
  },
  //删除店铺商品
  deleteStShop(index,goodsInfo, storesId) {
    return axios
      .delete("/stores/deleteStShop", {
        params: {
          index,goodsInfo, storesId
        },
      })
      .then(function (response) {
        // console.log("api",response);
        return response.data;
      });
  },
};
